<template>
    <div style="padding: 20px">
      <div class="headerBoxList">
        <svg width="24" height="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M9.85786 32.7574C6.23858 33.8432 4 35.3432 4 37C4 40.3137 12.9543 43 24 43C35.0457 43 44 40.3137 44 37C44 35.3432 41.7614 33.8432 38.1421 32.7574" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M24 35C24 35 37 26.504 37 16.6818C37 9.67784 31.1797 4 24 4C16.8203 4 11 9.67784 11 16.6818C11 26.504 24 35 24 35Z" fill="none" stroke="#333" stroke-width="4" stroke-linejoin="round"/><path d="M24 22C26.7614 22 29 19.7614 29 17C29 14.2386 26.7614 12 24 12C21.2386 12 19 14.2386 19 17C19 19.7614 21.2386 22 24 22Z" fill="none" stroke="#333" stroke-width="4" stroke-linejoin="round"/></svg>
        <span style="margin-left: 10px">GPS信息</span>
      </div>
      <div class="contentBoxYY" style="">
        <el-collapse v-model="activeName" accordion>
          <el-collapse-item style="" v-for="(item,index) in listData" :key="index" :title="'🚩 '+ item.titleKey+` （${item.content.length}行）`" :name="index">
              <div style="background: #282828;color: rgb(101, 177, 235);padding-left:20px;border: none !important;" v-for="(data,j) in item.content" :key="j">
                 {{ data }}
              </div>
          </el-collapse-item>
        </el-collapse>
      </div>
    </div>
</template>

  <script>
  import { getRxTmpPathApi } from '@/api/phoneInfo/index'
  export default {
    name: "gpsInfo",
    data() {
      return {
        activeName: 0,
        listData:[]
      };
    },
    mounted(){
      this.initFunction();
    },
    created() {
      
    },
    methods: {
      initFunction() {

        let node = this.$route.params.nodeData.data;
      let dataJson = {
        "proof_num":node.proof_num,
        "rxTmpPath":'/'+node.subtype
      }
      getRxTmpPathApi(dataJson).then(res=>{
        const stringData = res.data;
        // 设置截取标题数组
        const delimiters = [
          "Location Manager State:",
          "Event Log:",
          "Location Listeners:",
          "Active Records by Provider:",
          "Historical Records by Provider:"
        ];
  
        const dataArray = [];
        let currentData = "";
  
        for (let i = 0; i < delimiters.length; i++) {
          const delimiter = delimiters[i];
          const startIndex = stringData.indexOf(delimiter);
          const endIndex =i < delimiters.length - 1? stringData.indexOf(delimiters[i + 1]): stringData.length;
  
          if (startIndex !== -1 && endIndex !== -1) {
            const data = stringData.slice(startIndex, endIndex).trim();
            dataArray.push(data);
          }
        }
        let arr = [];
        // 格式化字符串数组为json数据
        for (let index = 0; index < dataArray.length; index++) {
          const element = dataArray[index];
          const originalString = element;
          const delimiter = "\n";
  
          const delimiterIndex = originalString.indexOf(delimiter);
  
          if (delimiterIndex !== -1) {
            const firstPart = originalString.substring(0, delimiterIndex).trim();
            const secondPart = originalString
              .substring(delimiterIndex + 1)
              .trim();
            let item = {
              titleKey: firstPart,
              content: secondPart.split("\n"),
            };
            arr.push(item);
          } else {
            console.log("Delimiter not found in the string.");
          }
          // arr.push(item)
        }
        this.listData = arr;
      })
    }
    },
  };
  </script>
  
  <style scoped>
  .headerBoxList {
    width: 100%;
    height: 50px;
    border-bottom: 1px solid #d2d2d2;
    display: flex;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
  }
  .contentBoxYY{
      width: 95%; 
      margin: 0 auto;
      overflow: hidden;
      height:95vh;
      overflow-y: auto;
  }
  @media screen and (min-width: 2360px) {
      .contentBoxYY{
          width: 95%; 
          margin: 0 auto;
          overflow: hidden;
          height:67vh;
          overflow-y: auto;
      }
  }
  
  </style>